package com.my.study.redis;

import java.io.IOException;
import java.net.Socket;

public class ZlxJedis {

    public static String set(Socket socket, String key, String value){

        StringBuffer sb = new StringBuffer();
        sb.append("*3").append("\r\n");
        sb.append("$3").append("\r\n");
        sb.append("SET").append("\r\n");
        sb.append("$").append(key.getBytes().length).append("\r\n");
        sb.append(key).append("\r\n");
        sb.append("$").append(value.getBytes().length).append("\r\n");
        sb.append(value).append("\r\n");
        byte [] response = new byte[2048];
        try{
            socket.getOutputStream().write(sb.toString().getBytes());
            socket.getInputStream().read(response);
        }catch (IOException e){
            e.printStackTrace();
        }
        return new String(response);
    }




    public static String get(Socket socket, String key){
        StringBuffer sb = new StringBuffer();
        sb.append("*2").append("\r\n");
        sb.append("$3").append("\r\n");
        sb.append("SET").append("\r\n");
        sb.append("$").append(key.getBytes().length).append("\r\n");
        sb.append(key).append("\r\n");

        byte [] response = new byte[2048];
        try{
            socket.getOutputStream().write(sb.toString().getBytes());
            socket.getInputStream().read(response);
        }catch (IOException e){
            e.printStackTrace();
        }
        return new String(response);
    }


    public static void main(String[] args) {


    }
}
